package org.aom.util;
/**
 * AOM页面DataGrid生成用工具
 * 只是简单的做了封装，目的是为了减少代码数量而已
 * @author Saya Yang 2009-6-10
 */
import java.util.Collection;
import org.operamasks.faces.component.grid.GridColumn;
import org.operamasks.faces.component.grid.GridColumnModel;
import org.operamasks.faces.component.grid.GridHeader;
import org.operamasks.faces.component.grid.GridHeaderCell;
import org.operamasks.faces.component.grid.GridHeaderModel;

public class GridUtil {
	
	/**
	 * 生成表格模型的方法，传入参数内容为表格列的id
	 * @param gids
	 * @return GridColumnModel
	 */
	public static GridColumnModel createGridColumnModel(String[] gids) {
		GridColumnModel columnModel = new GridColumnModel();
		for (String gid : gids) {
			columnModel.addColumn(new GridColumn(gid).width(100).enableSort(
					true));
		}
		return columnModel;
	}

	/**
	 * 生成表头模型的方法，传入参数为label
	 * @param headers
	 * @return GridHeaderModel
	 */
	public static GridHeaderModel createGridHeaderModel(String[] headers) {
		GridHeaderModel headerModel = new GridHeaderModel();
		GridHeader gh = new GridHeader();
		for (String header : headers) {
			gh.addCell(new GridHeaderCell().label(header));
		}
		return headerModel.headers(gh);
	}
	
	/**
	 * 生成表格模型的方法,参数为实现Collection接口的List或Set之类，底层调用数组方式
	 * @param gids
	 * @return GridColumnModel
	 */
	public static GridColumnModel createGridColumnModel(Collection<String> gids){
		return createGridColumnModel((String[]) gids.toArray());
	}
	/**
	 * 生成表头模型的方法,参数为实现Collection接口的List或Set之类，底层调用数组方式
	 * @param headers
	 * @return GridHeaderModel
	 */
	public static  GridHeaderModel createGridHeaderModel(Collection<String> headers){
		return createGridHeaderModel((String[])headers.toArray());
	}
}
